<template>
  <div>
    <el-row type="flex" justify="space-between">
      <el-button type="primary" plain icon="el-icon-plus" @click="dlgRecord()"
        >添加</el-button
      >
    </el-row>
    <!-- 案件记录情况 -->
    <el-table
      :data="dataList"
      border
      style="width: 90%; margin-top: 20px"
      v-loading="dataListLoading"
    >
      <el-table-column prop="contactTime" label="时间"> </el-table-column>
      <el-table-column prop="contactRecord" label="内容"> </el-table-column>
    </el-table>
    <el-pagination
      style="width: 90%"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <el-dialog title="添加记录" :visible.sync="dialogVisible" width="50%">
      <el-form
        :model="dlgFrom"
        ref="dlgFrom"
        :rules="rules"
        label-width="150px"
      >
        <el-form-item label="沟通日期" prop="contactTime">
          <el-date-picker
            v-model="dlgFrom.contactTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="沟通内容" prop="contactRecord">
          <el-input
            type="textarea"
            :rows="3"
            placeholder="请输入内容"
            v-model="dlgFrom.contactRecord"
            style="width: 520px"
          >
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmAdd()" :loading="saveLoading"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      saveLoading: false,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      dialogVisible: false,
      dlgFrom: {
        contactTime: "",
        contactRecord: "",
        csId: "",
      },
      rules: {
        contactRecord: [
          { required: true, message: "请输入沟通内容", trigger: "blur" },
        ],
        contactTime: [
          { required: true, message: "请选择沟通日期", trigger: "change" },
        ],
      },
    };
  },
  components: {},
  beforeMount() {},
  props: ["claimSettlement"],
  methods: {
    init: function () {
      this.dataListLoading = true;
      console.log("paramData==>", this.dataForm);
      this.$http({
        url: this.$http.adornUrl("/claim/contactrecord/pageList"),
        method: "POST",
        data: this.$http.adornData({
          page: this.pageIndex,
          pageSize: this.pageSize,
          params: this.claimSettlement.id,
        }),
      }).then(({ data }) => {
        this.dataListLoading = false;
        if (data && data.code === 0) {
          this.dataList = data.data.records;
          this.totalPage = data.data.total;
        } else {
          if (data && data.msg) {
            this.$message.warning(data.msg);
          }
          this.dataList = [];
          this.totalPage = 0;
        }
      });
    },
    dlgRecord: function () {
      this.dialogVisible = true;
      this.$nextTick(function () {
        // 打开新增弹窗前先重置表单 避免表单出现上一次新增的校验数据
        this.$refs.dlgFrom.resetFields();
      });
    },
    confirmAdd: function () {
      // this.dialogVisible = false;
      this.saveLoading = true;
      this.dlgFrom.csId = this.claimSettlement.id;
      console.log("this.dlgFrom", this.dlgFrom);
      this.$refs["dlgFrom"].validate((valid) => {
        if (valid) {
          console.log("valid==", valid);
          this.$http({
            url: this.$http.adornUrl("/claim/contactrecord/save"),
            method: "post",
            data: this.$http.adornData(this.dlgFrom),
          }).then(({ data }) => {
            this.saveLoading = false;
            if (data && data.code === 0) {
              this.dialogVisible = false;
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.init();
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        } else {
          this.saveLoading = false;
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.init();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.init();
    },
  },
};
</script>

<style>
</style>
